home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.io.InputStream;
- import java.net.URL;
-
- public class XYZApp extends Applet implements Runnable {
- // $FF: renamed from: md XYZChemModel
- XYZChemModel field_0;
- boolean painted = true;
- float xfac;
- int prevx;
- int prevy;
- float xtheta;
- float ytheta;
- float scalefudge = 1.0F;
- Matrix3D amat = new Matrix3D();
- Matrix3D tmat = new Matrix3D();
- String mdname;
- String message;
- Image backBuffer;
- Graphics backGC;
-
- public void init() {
- this.mdname = ((Applet)this).getParameter("model");
-
- try {
- this.scalefudge = Float.valueOf(((Applet)this).getParameter("scale"));
- } catch (Exception var1) {
- }
-
- this.amat.yrot((double)20.0F);
- this.amat.xrot((double)20.0F);
- if (this.mdname == null) {
- this.mdname = "model.obj";
- }
-
- ((Applet)this).resize(((Component)this).size().width <= 20 ? 400 : ((Component)this).size().width, ((Component)this).size().height <= 20 ? 400 : ((Component)this).size().height);
- }
-
- public void run() {
- InputStream var1 = null;
-
- try {
- Thread.currentThread().setPriority(1);
- var1 = (new URL(((Applet)this).getDocumentBase(), this.mdname)).openStream();
- XYZChemModel var2 = new XYZChemModel(var1);
- Atom.setApplet(this);
- this.field_0 = var2;
- var2.findBB();
- float var3 = var2.xmax - var2.xmin;
- float var4 = var2.ymax - var2.ymin;
- float var5 = var2.zmax - var2.zmin;
- if (var4 > var3) {
- var3 = var4;
- }
-
- if (var5 > var3) {
- var3 = var5;
- }
-
- float var6 = (float)((Component)this).size().width / var3;
- float var7 = (float)((Component)this).size().height / var3;
- this.xfac = 0.7F * (var6 < var7 ? var6 : var7) * this.scalefudge;
- this.backBuffer = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
- this.backGC = this.backBuffer.getGraphics();
- } catch (Exception var9) {
- ((Throwable)var9).printStackTrace();
- this.field_0 = null;
- this.message = ((Throwable)var9).toString();
- }
-
- try {
- if (var1 != null) {
- var1.close();
- }
- } catch (Exception var8) {
- }
-
- ((Component)this).repaint();
- }
-
- public void start() {
- if (this.field_0 == null && this.message == null) {
- (new Thread(this)).start();
- }
-
- }
-
- public void stop() {
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- this.prevx = var2;
- this.prevy = var3;
- return true;
- }
-
- public boolean mouseDrag(Event var1, int var2, int var3) {
- this.tmat.unit();
- float var4 = (float)(this.prevy - var3) * (360.0F / (float)((Component)this).size().width);
- float var5 = (float)(var2 - this.prevx) * (360.0F / (float)((Component)this).size().height);
- this.tmat.xrot((double)var4);
- this.tmat.yrot((double)var5);
- this.amat.mult(this.tmat);
- if (this.painted) {
- this.painted = false;
- ((Component)this).repaint();
- }
-
- this.prevx = var2;
- this.prevy = var3;
- return true;
- }
-
- public void update(Graphics var1) {
- if (this.backBuffer == null) {
- var1.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- }
-
- this.paint(var1);
- }
-
- public void paint(Graphics var1) {
- if (this.field_0 != null) {
- this.field_0.mat.unit();
- this.field_0.mat.translate(-(this.field_0.xmin + this.field_0.xmax) / 2.0F, -(this.field_0.ymin + this.field_0.ymax) / 2.0F, -(this.field_0.zmin + this.field_0.zmax) / 2.0F);
- this.field_0.mat.mult(this.amat);
- this.field_0.mat.scale(this.xfac, -this.xfac, 16.0F * this.xfac / (float)((Component)this).size().width);
- this.field_0.mat.translate((float)(((Component)this).size().width / 2), (float)(((Component)this).size().height / 2), 8.0F);
- this.field_0.transformed = false;
- if (this.backBuffer != null) {
- this.backGC.setColor(((Component)this).getBackground());
- this.backGC.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- this.field_0.paint(this.backGC);
- var1.drawImage(this.backBuffer, 0, 0, this);
- } else {
- this.field_0.paint(var1);
- }
-
- this.setPainted();
- } else {
- if (this.message != null) {
- var1.drawString("Error in model:", 3, 20);
- var1.drawString(this.message, 10, 40);
- }
-
- }
- }
-
- private synchronized void setPainted() {
- this.painted = true;
- this.notifyAll();
- }
-
- private synchronized void waitPainted() {
- while(!this.painted) {
- try {
- this.wait();
- } catch (Exception var1) {
- }
- }
-
- this.painted = false;
- }
- }
-